package com.oocl.main;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.util.ArrayList;
import java.util.List;

import javax.jms.JMSException;

import com.oocl.jsonparse.JSONParse;
import com.oocl.mqService.MQservice;

import POJO.Books;

public class MQOffer {
	public static void main(String[] args) {
			long start = System.currentTimeMillis();
			try {
				ObjectInputStream oin = new ObjectInputStream(new FileInputStream("BOOKS.txt"));
				List<Books> list = new ArrayList<Books>();
				JSONParse jp = new JSONParse();
				MQservice mqs = new MQservice();
				
				int index = 0;              //标记循环遍历了多少个对象
				Books book = null;
				while((book = (Books) oin.readObject()) != null){
					index++;
					list.add(book);
					if(list.size() == 4350){
						String[] result = jp.parse(list);
						mqs.offerMQ(result);
						list.clear();
					}
				}
				System.out.println(index);
				mqs.release();
			} catch (FileNotFoundException e) {
				e.printStackTrace();
			} catch (ClassNotFoundException e) {
				e.printStackTrace();
			} catch (IOException e) {
				e.printStackTrace();
			} catch (JMSException e) {
				e.printStackTrace();
			}
			long end = System.currentTimeMillis();
			System.out.println((end-start)  + "毫秒");
		
		
	}
}
